<template>
  <div>
    <h3>添加书籍</h3>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="书名" prop="book_name" class="aa">
        <el-input
          type="text"
          v-model="ruleForm.book_name"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="价格" prop="book_price" class="aa">
        <el-input
          type="text"
          v-model="ruleForm.book_price"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="库存" prop="book_num" class="aa">
        <el-input v-model="ruleForm.book_num"></el-input>
      </el-form-item>
      <el-form-item label="书籍介绍" prop="book_text" class="aa">
        <el-input v-model="ruleForm.book_text"></el-input>
      </el-form-item>
      <el-form-item label="作者" prop="book_author" class="aa">
        <el-input v-model="ruleForm.book_author"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addbooks">添加</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Axios from "axios";
export default {
  name: "",
  data() {
    return {
      ruleForm: {
        book_name: "",
        book_price: "",
        book_num: "",
        book_text: "",
        create_time: "",
        book_author: "",
      },
    };
  },
  props: {},

  components: {},

  created() {},

  mounted() {},

  methods: {
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    addbooks() {
      Axios.post("http://127.0.0.1:5000/books/addbooks", this.ruleForm).then(
        (res) => {
          console.log("添加的响应", res.data);
          if (res.data.code == 200) {
            this.$notify({
              title: "成功",
              message: "添加成功",
              type: "success",
            });
            this.$router.push('/books')
          } else {
            this.$notify.error({
              title: "错误",
              message: res.data.message,
            });
          }
        }
      );
    },
  },

  computed: {},

  watch: {},

  directives: {},

  filters: {},
};
</script>

<style>
.aa {
  width: 400px;
}
</style>
